/*
 *  * Copyright (c) 2020-2030  Xiamen Nascent Corporation. All rights reserved. 
 *
 *  * https://www.nascent.cn
 *
 *  * 厦门南讯股份有限公司创立于2010年，是一家始终以技术和产品为驱动，帮助大消费领域企业提供客户资源管理（CRM）解决方案的公司。
 *  * 福建省厦门市软件园二期观日路22号401
 *  * 客服电话 400-009-2300
 *  * 电话 +86（592）5971731 传真 +86（592）5971710
 *
 *  * All source code copyright of this system belongs to Xiamen Nascent Co., Ltd.
 *  * Any organization or individual is not allowed to reprint, publish, disclose, embezzle, sell and use it for other illegal purposes without permission!
 */

package com.example.demo.common;

import com.example.demo.common.exception.SentinelLimitException;
import com.google.common.base.MoreObjects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description: 异常统一处理类
 * @Author: XUZHILONG
 * @Date: 2019/7/22 18:43
 * @Version: 1.0
 */
@RestControllerAdvice
@Slf4j
public class BadRequestExceptionHandler {

    @ExceptionHandler(SentinelLimitException.class)
    public BaseResponse sentinelLimitException(SentinelLimitException e) {
        log.error("流量拥堵", e);
        BaseResponse response = new BaseResponse();
        response.setSuccess(false);
        response.setCode(String.valueOf(e.getErrorCode()));
        response.setMsg(MoreObjects.firstNonNull(e.getMessage(), "服务未知异常，请联系管理员"));
        return response;
    }

}
